<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>员工列表</title>
    <script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"></script>
    <style>
        table {
            margin-top: 30px;
            /*margin: 0px auto;*/
            margin-left: 200px;
            width: 1000px;
            border-collapse: collapse;

        }

        table tr {
            font-size: 2em;
            font-weight: bold;
            margin: 1em 0;
        }

        th, td {
            border: 1px solid #999;
            text-align: center;
            padding: 20px 0;
        }

        table thead tr {
            background-color: #008c8c;
            color: #fff;
        }

        table tbody tr:nth-child(odd) {
            background-color: #eee;
        }

        table tbody tr:hover {
            background-color: #ccc;
        }

        table tbody tr td:first-child {
            color: #f40;
        }

        table tfoot tr td {
            text-align: right;
            padding-right: 20px;
        }

    </style>
</head>
<body>

<div style="width: 80%;margin-left: 50px">
    <table id="emp">
        <thead>
        <div style="width: 300px; margin-left: 550px;" >
            <input type="text" id="ename" placeholder="请输入搜索关键字" style="border:2px solid #ddd; font-size: larger">
        <input type="button" id="search" value="搜"  style="border:2px solid #ddd; font-size: larger">
            <input type="text" id="d" placeholder="请输入搜索关键字" style="border:2px solid #ddd; font-size: larger">
            <input type="button" id="del" value="删"  style="border:2px solid #ddd; font-size: larger">
            <input type="text" id="username" placeholder="请输入搜索关键字" style="border:2px solid #ddd; font-size: larger">
            <input type="button" id="ud" value="改"  style="border:2px solid #ddd; font-size: larger">


        </div>
        <tr>
            <th>工号</th>
            <th>姓名</th>
            <th>职位</th>
            <th>工资</th>

        </tr>
        </thead>
        <tbody id="tbody">
        </tbody>
    </table>
</div>
<div style="margin:20px auto; width: 250px">
    <a href="javascript:void(0);" id="first" class="page">首页</a>&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="javascript:void(0);" id="pre" class="page">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="javascript:void(0);" id="next" class="page">下一页</a>&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="javascript:void(0);" id="last" class="page">尾页</a>
</div>

<script>
    var currPage;
    var tpages;
    $(/*document).ready(*/function () {
        var getEmpList = function (curr) {//给函数起名，传参curr当前页数
            $.ajax({
                url: "/showPage",
                type: "post",
                dataType: "json",
                data: {
                    pageSize: 4,
                    pageNum: curr || 1,
                    ename:$('#ename').val()
                },
                success: function (data) {
                    $("#tbody").find("tr").remove();
                    var tbody = $('#tbody');
                    $.each(data.Emps, function (index, emp) {
                        tbody.append('<tr><input type="checkbox" name="msg"><td>' + emp.empno + '</td><td>' + emp.ename + '</td><td>' + emp.job + '</td><td>' + emp.sal + '</td></tr>');
                    });
                    currPage = data.pageNum;
                    tpages = data.totalpages;
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log("Error: " + textStatus);
                }

            });
        }
        $(".page").click(function () {
            var flag = $(this).attr("id");
            if (flag == "first") {
                getEmpList(1);
            } else if (flag == "pre") {
                currPage--;
                getEmpList(currPage);
            } else if (flag == "next") {
                currPage++;
                getEmpList(currPage);
            } else if (flag == "last") {
                getEmpList(tpages)
            }

        })

        getEmpList();
        $('#search').click(function () {
            getEmpList();
        })
    });

</script>
</body>
</html>